package com.cqu.lpss.service.impl;

import com.cqu.lpss.mapper.ScoringCriterionsMapper;
import com.cqu.lpss.pojo.PageBean;
import com.cqu.lpss.pojo.Scoringcriterions;
import com.cqu.lpss.service.ScoringCriterionsInterface;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@Slf4j
public class ScoringCriterionsImpl implements ScoringCriterionsInterface {
    @Autowired
    ScoringCriterionsMapper scoringCriterionsMapper;
    @Override
    public List<Scoringcriterions> findByClass(Integer classId) {
        List<Scoringcriterions> criterions = scoringCriterionsMapper.findByClass(classId);
        return criterions;
    }

    @Override
    public PageBean<Scoringcriterions> list(int page, int pageSize, Integer classId, String scName) {
        PageHelper.startPage(page,pageSize);
        List<Scoringcriterions> scoringcriterionsList = scoringCriterionsMapper.list(classId, scName);
        Page<Scoringcriterions> pagelist = (Page<Scoringcriterions>) scoringcriterionsList;
        PageBean<Scoringcriterions> pageBean = new PageBean<>(pagelist.getTotal(),pagelist);
        return pageBean;
    }

    @Override
    public int add(Scoringcriterions scoringcriterion) {
        int ans = scoringCriterionsMapper.add(scoringcriterion.getClassId(),scoringcriterion.getScName(),scoringcriterion.getScContent(),scoringcriterion.getScWeight());
        return ans;
    }

    @Override
    public int edit(Scoringcriterions scoringcriterion) {
        int ans = scoringCriterionsMapper.edit(scoringcriterion.getScId(),
                scoringcriterion.getClassId(),
                scoringcriterion.getScName(),
                scoringcriterion.getScContent(),
                scoringcriterion.getScWeight());
        return ans;
    }
}
